﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Threading;
using Microsoft.PointOfService;

namespace POS
{
    public partial class StartupScreen : DevExpress.XtraEditors.XtraForm
    {
        public static Thread StartupProcedures;

        public StartupScreen()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void StartupScreen_Load(object sender, EventArgs e)
        {
            StartupProcedures = new Thread(new ThreadStart(Startup1));
            StartupProcedures.Name = "STARTUP THREAD";
            StartupProcedures.Start();
        }

        void Startup1()
        {
            string[] lookup = new string[] { "127.0.0.1", "www.yahoo.com" };
            Thread.Sleep(250);

            try
            {

                progressPanel1.Description = "Checkinging Network Connection";
                Thread.Sleep(250);
                if (NetworkConnectionClass.CheckNetworkAddress(lookup))
                {
                    try
                    {
                        progressPanel1.Description = "Checkinging Database Connection";
                        Thread.Sleep(250);
                        if (DataTablesClass.IsServerConnected())
                        {

                            try
                            {
                                progressPanel1.Description = "Loading Employee's Information";
                                Thread.Sleep(500);
                                DataTablesClass.GetDataTableEmployeeLogin();
                                //DataTablesClass.GetDataTableEmployeeInfo();
                                DataTablesClass.GetDataTableEmployeeTimeSheet();
                                //DataTablesClass.GetDataTableEmployeeTips();

                                progressPanel1.Description = "Loading Menu Items";
                                Thread.Sleep(500);
                                DataTablesClass.GetDataTableMenuItems();
                                DataTablesClass.GetDataTableMenuItemsCategory();

                                //progressPanel1.Description = "Loading Receipts";
                                //Thread.Sleep(500);
                                //DataTablesClass.GetDataTableReceipts();
                                //DataTablesClass.GetDataTableReceiptsData();

                                progressPanel1.Description = "Loading Seating chart";
                                Thread.Sleep(1000);

                            }
                            catch (Exception exs)
                            {
                                MessageBox.Show(exs.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Unable to connect to Database");
                        }
                    }
                    catch (Exception exs)
                    {
                        MessageBox.Show("Unable to connect to Database");
                    }
                }
            }
            catch (Exception E)
            {
            }

            //try
            //{
            //    progressPanel1.Description = "Loading Card Reader";

            //    PosExplorer myPosExplorer = new PosExplorer();
            //    DeviceCollection myDevices;

            //    myDevices = myPosExplorer.GetDevices(DeviceType.Msr);

            //    foreach (DeviceInfo devInfo in myDevices)
            //    {
            //        if (devInfo.ServiceObjectName == "Microsoft Msr Simulator")
            //        {
            //            StaticProperties.CreditCardReader = myPosExplorer.CreateInstance(devInfo) as Msr;
            //        }
            //    }
            //}
            //catch (Exception EX)
            //{
            //    MessageBox.Show("UNABLE TO CONNECT TO CARD READER");
            //}

            //try
            //{
            //    progressPanel1.Description = "Loading POS Station Printer";

            //    PosExplorer myPosExplorer = new PosExplorer();
            //    DeviceCollection myDevices;

            //    myDevices = myPosExplorer.GetDevices(DeviceType.PosPrinter);

            //    foreach (DeviceInfo devInfo in myDevices)
            //    {
            //        if (devInfo.ServiceObjectName == "Microsoft PosPrinter Simulator")
            //        {
            //            StaticProperties.StationPrinter = myPosExplorer.CreateInstance(devInfo) as PosPrinter;
            //        }
            //    }
            //}
            //catch (Exception EX)
            //{
            //    MessageBox.Show("UNABLE TO CONNECT TO STATION PRINTER");
            //}


            finally
            {
                this.Close();
            }
        }


    }
}